package week08;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ArrayListIntegerStack implements IntegerStack{
	private List<Integer> arrList=new ArrayList<>();
	
	public static void main(String[] args) {
		ArrayListIntegerStack arrayList=new ArrayListIntegerStack();
		Scanner sc=new Scanner(System.in);
		int m=sc.nextInt();
		for(int i=0;i<m;i++)
			System.out.println(arrayList.push((Integer)sc.nextInt()));
		System.out.println(arrayList.peek()+","+arrayList.empty()+","+arrayList.size());
		System.out.println(arrayList.toString());
		int n=sc.nextInt();
		for(int i=0;i<n;i++)
			System.out.println(arrayList.pop());
		System.out.println(arrayList.peek()+","+arrayList.empty()+","+arrayList.size());
		System.out.println(arrayList.toString());

	}

	public Integer push(Integer item) {
		if(item==null)
		return null;
		arrList.add(item);
		return item;
	}

	public Integer pop() {
		if(arrList.isEmpty())
		return null;
		return arrList.remove(arrList.size()-1);
	}

	public Integer peek() {
		if(arrList.isEmpty())
		return null;
		return arrList.get(arrList.size()-1);
	}

	public boolean empty() {
		return arrList.isEmpty();
	}

	public int size() {
		return arrList.size();
	}

	public String toString() {
		return arrList.toString();
	}
	

}
